<?php
require_once APP . '/application/controllers/FrontAction.php';

/**
 * 首页
 */
class StatController extends FrontAction
{
    /**
     * 本controller通用模块
     */
    public function init ()
    {
    }
    
    public function indexAction()
    {
    	
    }
    
    /**
     * 首页广告点击统计
     *
     */
    public function aAction()
    {
    	$id = (int)$this->getParam("id");
    	$this->db->update("adlist", array("hits" => 'hits+1'), "id=" . $id);
    }
    
    /**
     * 支持家族
     *
     */
    public function jzAction()
    {
    	$id = (int)$this->getParam("id");
    	
    	$limit = 1;// 每日最多投3票
    	$ip = $this->getIp(true);
    	
    	$dayline = strtotime("0 day 00:00:00");
    	$row = $this->db->fetchRow("select * from iplimit where ip=?", array($ip));
    	
    	if (!empty($row) && $row['dayline'] == $dayline && $row['num'] >= $limit){
    		$this->showmessage("每个IP每日最多支持" . $limit . '次');
    	}
    	
    	if (empty($row)){
    		$this->db->insert("iplimit", array("ip" => $ip, "dayline" => $dayline, 'num' => 1));
    	}else{
    		if ($row['dayline'] != $dayline){
    			$this->db->update("iplimit", array("dayline" => $dayline, "num" => 1), "ip='" . $ip . "'");
    		}else{
    			$this->db->update("iplimit", array("num" => 'num+1'), "ip='" . $ip . "'");
    		}
    	}
    	
    	$this->db->update("jzlist", array("hits" => "hits+1"), "id=" . $id);
    	
    	$result = array("status" => 1, "message" => "支持成功");
    	echo json_encode($result);
    }
    
    /**
     * 首页私服服务器点击统计
     *
     */
    public function dAction()
    {
    	$id = (int)$this->getParam("id", 0);
    	
    	$this->db->update("sfdata", array("urlhits" => "urlhits+1"), "id=" . $id);
    }
}
